﻿using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using Inovout.Gis.Geometry;
using System;
using Inovout.Gis;

namespace Inovout.ArcGis
{
    public class PolyLineInfo : GeometryInfo, ILineInfo
    {
        #region Constructor
        internal protected PolyLineInfo(ArcGisRow row)
            : base(row)
        {
        }
        public PolyLineInfo(IPolyline arcPolyLine)
            : base(arcPolyLine)
        {
        }

        #endregion


        #region Length
        public double Length
        {
            get
            {
                return CalculateLength();
            }
        }
        protected virtual double CalculateLengthFromGeometry()
        {
            return 0;
        }

        protected readonly string LengthFieldName = "CD";//"Length";
        protected virtual double CalculateLengthFromFeature()
        {
            double length;
            Row.TryGetValue<double>(LengthFieldName, out length);
            return length;
        }
        private double CalculateLength()
        {
            double length = CalculateLengthFromFeature();
            if (length == 0 && Row != null)
            {
                length = CalculateLengthFromGeometry();
            }
            return length;
        }

        #endregion

        #region Width
        public double Width
        {
            get
            {
                return CalculateWidth();
            }
        }
        protected virtual double CalculateWidthFromGeometry()
        {
            return 0;
        }

        protected readonly string WidthFieldName = "KD";//"Width";
        protected virtual double CalculateWidthFromFeature()
        {
            double width;
            Row.TryGetValue<double>(WidthFieldName, out width);
            return width;

        }
        private double CalculateWidth()
        {
            double width = CalculateWidthFromFeature();
            if (width == 0 && Row != null)
            {
                width = CalculateWidthFromGeometry();
            }
            return width;
        }

        #endregion

        #region Area

        protected override double CalculateAreaFromFeature()
        {
            if (base.CalculateAreaFromFeature() == 0)
            {
                return Length * Width;
            }
            else
            {
                return 0;
            }
        }


        #endregion


    }
}
